package com.primaryedu.adapter;

import com.jauker.widget.BadgeView;
import com.primaryedu.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainMenuAdapter extends BaseAdapter {

    private final int isRead;
    private final String status;
    private LayoutInflater inflater;
    @SuppressWarnings("unused")
    private Context context;

    private Integer[] imgs = new Integer[]{
            R.drawable.function_01,
            R.drawable.function_02,
            R.drawable.function_03,
            R.drawable.function_04,
            R.drawable.function_05,
            R.drawable.function_06,
            R.drawable.function_07,
            R.drawable.icon_app_14,
            R.drawable.icon_app_15,
    };

    private Integer[] texts = new Integer[]{
            R.drawable.icon_text_01,
            R.drawable.icon_text_02,
            R.drawable.icon_text_03,
            R.drawable.icon_text_04,
            R.drawable.icon_text_05,
            R.drawable.icon_text_06,
            R.drawable.icon_text_07,
            R.drawable.icon_text_08,
            R.drawable.icon_text_09,
    };

    private String[] str = new String[]{
            "特色文化", "校园安全", "校园新闻", "移动办公", "成长脚印", "通知公告", "家校互动","留言板","家校视频"
    };
    private BadgeView badgeView;

    public MainMenuAdapter(Activity context, int isRead, String status) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.isRead = isRead;
        this.status = status;
    }

    @Override
    public int getCount() {
        return imgs.length;
    }

    @Override
    public Object getItem(int arg0) {
        return str[arg0];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("NewApi")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_menu, null);
            viewHolder.textView = (TextView) convertView.findViewById(R.id.item_text);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.item_image);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        badgeView = new BadgeView(context);
        viewHolder.imageView.setImageResource(imgs[position]);
//        viewHolder.textView.setText(str[position]); 

        viewHolder.textView.setBackgroundResource(texts[position]);
        //设置有无最新未读消息
        if (position == 5) {
            Log.i("yy", "getView:isRead==== " + isRead);
            if (isRead != 0) {
                badgeView.setTargetView(viewHolder.imageView);
                badgeView.setBadgeCount(isRead);
            }
        }
        //设置有无最新视频通话
        if (position == 8){
            Log.i("yy", "getView:status==== " + status);
            if (status != "0") {
                badgeView.setTargetView(viewHolder.imageView);
                badgeView.setBadgeCount(Integer.parseInt(status));
            }
        }
        return convertView;
    }

    class ViewHolder {
        ImageView imageView;
        TextView textView;
    }

}
